package com.zxinlee.account.service.impl;

import com.zxinlee.account.mapper.AccountMapper;
import com.zxinlee.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Transactional
    @Override
    public void decrease(long userId, BigDecimal money) {

        accountMapper.decrease(userId, money);

        if (Math.random() < 0.3) {
            throw new RuntimeException("模拟Account异常");
        }
    }
}
